$(document).ready(function () {
    //初始化swiper-案例
    let divceW = document.body.clientWidth
    let divceH = window.innerHeight
    let animationDistance = (divceH / 5).toFixed(0)
    let topNumAnimation = false
    let BottomNUmAnimation = false
    console.log('divce', divceH, divceW);


    var exampleSwiper = new Swiper(".example-list-swiper", {
        slidesPerView: divceW < 1024 ? 2 : 3,
        spaceBetween: divceW <= 1024 ? 20 : 80,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });
    //初始化swiper-生态
    var ecosystemSwiper = new Swiper(".ecosystem-company-swiper", {
        // autoplay: true,
        slidesPerView: "auto",
        spaceBetween: 50,
        speed: 900,
        loop: true,



        autoplay: {
            delay: 1000
        }
    });
    //初始化swiper-合作伙伴
    var partnersSwiper = new Swiper(".partners-list-swiper", {
        // autoplay: true,
        direction: 'vertical',
        slidesPerView: divceW >= 1024 ? 2 : 3,
        speed: 900,
        loop: true,
        autoplay: {
            delay: 1000
        }
    });

    partnersSwiper.disableTouchControl = true
    partnersSwiper.disableMousewheelControl = true
    //初始化swiper-新闻
    var newsSwiper = new Swiper(".news-list-swiper", {
        slidesPerView: divceW < 1024 ? 'auto' : 3,
        spaceBetween: 20,
        navigation: {
            nextEl: '.new-swiper-button-next',
            prevEl: '.new-swiper-button-prev',
        },
    });
    //配置运营选择事件

    $('.plan-list-item').each(function () {
        let _this = this
        $(_this).on('click', function () {
            // 显示对应图片
            let parentA = $(this).parents('a')
            let key = parentA.data('key') * 1 - 1
            $(`${divceW < 768 ? '.plan-h5 ' : ''}.box-left-info`).eq(key).siblings().hide()
            $(`${divceW < 768 ? '.plan-h5 ' : ''}.box-left-info`).eq(key).show()
            // 取消其他类名
            $('.plan-list-item').each(function () {
                $(this).removeClass('plan-list-item-active')
                $(_this).addClass('plan-list-item-active')
            });
        })
    });
    //页面显示过度动画插件
    new WOW().init()

    //数字过度处理
    var options = {
        useEasing: true,  // 过渡动画效果，默认ture
        useGrouping: true,  // 千分位效果，例：1000->1,000。默认true
        separator: '',   // 使用千分位时分割符号
        decimal: '.',   // 小数位分割符号
        prefix: '',    // 前置符号
        suffix: ''    // 后置符号，可汉字
    }
    var countNum = new CountUp('count-title', 1, 18, 0, 2, options);
    var countNum2 = new CountUp('count-title2', 1, 500, 0, 1, options);
    var countNum3 = new CountUp('count-title3', 10, 2000, 0, 1, { ...options, suffix: '+' });

    var partnersNum = new CountUp('partners-item-num', 5, 65, 0, 2, { ...options, suffix: '万+' });
    var partnersNum2 = new CountUp('partners-item-num2', 50, 300, 0, 2, { ...options, suffix: '万+' });

    //数字是否在可视区域-配置过度动画
    function isInViewport(_this) {
        var elementTop = $(_this).offset().top;
        var elementBottom = elementTop + $(_this).outerHeight();
        var viewportTop = $(window).scrollTop() - animationDistance * 1;
        var viewportBottom = viewportTop + $(window).height();
        return elementBottom > viewportTop && elementTop < viewportBottom;
    }

    $(document).on('scroll', () => {
        if (!topNumAnimation && isInViewport($('.count-box'))) {
            topNumAnimation = true
            setTimeout(() => {
                countNum.start()
                countNum2.start()
                countNum3.start()
            }, 300);
        }

        if (!BottomNUmAnimation && isInViewport($('.partners-item-num'))) {
            BottomNUmAnimation = true
            setTimeout(() => {
                partnersNum.start()
                partnersNum2.start()
            }, 300);
        }
    })
})